package com.atguigu.tingshu.user.factory.impl;

import com.atguigu.tingshu.user.factory.StrategyFactory;
import com.atguigu.tingshu.user.strategy.ItemTypeStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author atguigu-mqx
 * @ClassName StrategyFactoryImpl
 * @description: TODO
 * @date 2025年04月26日
 * @version: 1.0
 */
@Service
public class StrategyFactoryImpl implements StrategyFactory {

    //  如何处理
    /**
     * 将IOC容器中ItemTypeStrategy接口下所有实现类对象注入到Map中
     * Map中Key：Bean对象ID
     * Map中Value：实现类对象
     * {"1001":购买类型为专辑策略类对象}
     * {"1002":购买类型为声音策略类对象}
     * {"1003":购买类型为会员策略类对象}
     */
    @Autowired
    private Map<String, ItemTypeStrategy> strategyMap;
    @Override
    public ItemTypeStrategy getStrategy(String type) {
        //  1001=AlbumStrategy 1002=TrackStrategy 1003=VipStrategy
        if (strategyMap.containsKey(type)){
            //  返回数据
           return strategyMap.get(type);
        }
        //  默认返回空
        return null;
    }
}
